package org.mokusakura.web.interceptor.config;

import org.mokusakura.constant.ServletUrlConstant;
import org.mokusakura.web.interceptor.LoginFirstInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private LoginFirstInterceptor loginFirstInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //FIXME 使用前后端分离之后，这里注册的Interceptor应当是别的认证方式的Interceptor。
        registry.addInterceptor(loginFirstInterceptor)
                .addPathPatterns(ServletUrlConstant.REMOVE_ITEM_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.ACCOUNT_INFORMATION_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.CART_PAGE_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.CART_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.CHANGE_ACCOUNT_INFORMATION_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.CHECK_OUT_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.CONFIRM_ORDER_PAGE_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.MAKE_ORDER_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.NEW_ORDER_PAGE_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.ORDER_DETAIL_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.ORDER_LIST_PAGE_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.SHIPPING_ADDRESS_SERVLET_URL)
                .addPathPatterns(ServletUrlConstant.UPDATE_QUANTITY_SERVLET_URL);
    }
}
